package zhou.cutfruit.view;

import zhou.cutfruit.R;
import zhou.cutfruit.util.PreparedSoundSingle;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.BitmapDrawable;
import android.widget.LinearLayout;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;



public class MyLinearlayoutView extends LinearLayout {


	Context context;
	int currentX;
	int currentY;

	public MyLinearlayoutView(Context context) {

		super(context);
		this.context = context;
		
	

	}

	public MyLinearlayoutView(Context context, AttributeSet attrs) {
		super(context, attrs);
		this.context = context;
		
	}

	@Override
	protected void onDraw(Canvas canvas) {
		super.onDraw(canvas);
		Paint p = new Paint();
		Bitmap bitmap = ((BitmapDrawable)context.getResources().getDrawable(R.drawable.wartermelon)).getBitmap();
		
		
		
		p.setColor(Color.RED);

		canvas.drawBitmap(bitmap,380,290, p);
	}

	
	@Override
	public boolean onTouchEvent(MotionEvent event) {

		switch (event.getAction()) {
		case MotionEvent.ACTION_DOWN:
			this.currentX = (int) event.getX();
			this.currentY = (int) event.getY();
			PreparedSoundSingle.getInstance().playCutSound();
			

			this.invalidate();

			break;

		case MotionEvent.ACTION_MOVE:
			this.currentX = (int) event.getX();
			this.currentY = (int) event.getY();
			Log.i("motionEvent_move", "x"+currentX+"   y"+currentY);

			this.invalidate();
			break;

		case MotionEvent.ACTION_UP:
			this.currentX = (int) event.getX();
			this.currentY = (int) event.getY();
			// soundPool.play(soundMap.get(2), 1, 1, 0, 0, 1);
			this.invalidate();
			break;

		default:
			break;
			
		}

		// this.currentX = (int)event.getX();
		// this.currentY = (int)event.getY();
		// this.invalidate();
		return true;

	}

	
	
	
	
	
	/*
	 * @Override public boolean dispatchTouchEvent(MotionEvent ev) {
	 * this.currentX = (int)ev.getX(); this.currentY = (int)ev.getY();
	 * this.invalidate();
	 * 
	 * 
	 * 
	 * 
	 * 
	 * 
	 * switch (ev.getAction()) { case MotionEvent.ACTION_DOWN:
	 * //soundPool.play(soundMap.get(1), 1, 1, 0, 0, 1); this.currentX =
	 * (int)ev.getX(); this.currentY = (int)ev.getY(); this.invalidate();
	 * 
	 * 
	 * break;
	 * 
	 * case MotionEvent.ACTION_MOVE: //soundPool.play(soundMap.get(1), 1, 1, 0,
	 * 0, 1);
	 * 
	 * break;
	 * 
	 * case MotionEvent.ACTION_UP: //soundPool.play(soundMap.get(1), 1, 1, 0, 0,
	 * 1); this.currentX = (int)ev.getX(); this.currentY = (int)ev.getY();
	 * this.invalidate(); break;
	 * 
	 * default: break; }
	 * 
	 * return false; }
	 */

}
